import logging

from django.shortcuts import render, redirect
from rest_framework.views import APIView

from saas_main import models

log = logging.getLogger(__name__)
from django.conf import settings
from saas_main.tasks import *


def index(request):
    log.info(f'进入首页了{settings.DEBUG}')
    return render(request, 'index.html')


def show_test(request):
    log.error(f'这是测试错误日志')
    a = get_jenkins_list.delay()
    return render(request, 'test-1.html')


class Test(APIView):
    def post(self, request):
        return redirect(
            "https://unitradeprod-sandbox.dl.alipaydev.com/appAssign.htm?alipay_exterface_invoke_assign_target=invoke_136e65362411fbe969b804e4721afed5&alipay_exterface_invoke_assign_sign=d_b_fatu_c_j_qc12_zf_l_t_umasu8_n_y_a_p_v_xh_p_d_s_amh_a_f_ey_imx_zan_gc6_t_hks7_q%3D%3D")


def price(request):
    qs = models.UserRightConfig.objects.all()
    return render(request, 'price.html', {'prices': qs})


def order(request):
    right = request.GET.get("right")
    quantity = request.GET.get("quantity")
    right_obj = models.UserRightConfig.objects.get(id=right)
    params = {
        'right': right,
        "quantity": quantity,
        "right_obj": right_obj,
        "total_price": int(quantity) * right_obj.price
    }
    return render(request, 'order.html', params)


def order_list(request):
    qs = models.RightOrder.objects.filter(order_by_user=request.user).order_by("-create_time")
    params = {
        "orders": qs
    }
    return render(request, 'order_list.html', params)
